<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>
        计算属性
    </title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>

    <div id="root">
        <h1>4 计算属性实现</h1>
        姓：<input type="text" v-model="firstName">
        <br> </br>
        名：<input type="text" v-model="lastName">
        <br> </br>
        <!-- 姓名：<span>{{firstName.slice(0,3)}}-{{lastName}}</span> -->
        姓名：<span> {{fullName}} </span><br> </br>
        姓名：<span> {{fullName}} </span><br> </br>
        姓名：<span> {{fullName}} </span><br> </br>
        姓名：<span> {{fullName}} </span><br> </br>
        姓名：<span> {{fullName}} </span><br> </br>
        <button>点我计算结果</button>
    </div>
</body>

<script type="text/javascript">
    Vue.config.productionTip = false
    let vm = new Vue({
        el: '#root',
        data() {
            return {
                firstName: '张',
                lastName: '三',
          
            }
        },
        computed: {//computed  比methods 省  注意fullname 写法
// 相当于get 方法
            fullName() {
                console.log("调用了e")
                return this.firstName + '-' + this.lastName
            },
            fullName: {
                // get() {
                //     console.log("调用了e")
                //     return this.firstName + '-' + this.lastName

                // },
                //当fullname 被修改时候
                set(value) {
                    console.log('set', value)
                    const arr = value.split('-')
                    this.firstName = arr[0]
                    this.lastName = arr[1]
                }
            }
        },
    })
</script>

</html>